package com.iman.sumer.service.impl.space;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.Constants;
import com.iman.common.hibernate.TemplateQLService;
import com.iman.common.support.Page;
import com.iman.common.util.IdCreater;
import com.iman.sumer.service.space.CollectService;
import com.iman.sumer.vo.sapce.CollectFolderVo;
import com.iman.sumer.vo.sapce.CollectInfoVo;

@Service("collectService")
public class CollectServiceImpl implements CollectService {

	@Inject
	TemplateQLService templateQLService;

	public Page<CollectInfoVo> getCollectInfoPage(Map<String, Object> params) {
		Integer pageIndex = (Integer) params.get(Constants.PAGE_INDEX_KEY);
		Integer pageSize = (Integer) params.get(Constants.PAGE_SIZE_KEY);
		return templateQLService.findByPagedSQLBeanQuery("get_collect_info_page", params,
				Page.getStartOfPage(pageIndex, pageSize), pageSize, CollectInfoVo.class);
	}

	public Integer getCollectFolderCnt(Map<String, Object> params) {
		BigInteger cnt = (BigInteger) templateQLService.findSQL("get_collect_folder_cnt", params);
		return cnt.intValue();
	}

	public List<CollectFolderVo> getCollectFolderStatic(Map<String, Object> params) {
		return templateQLService.findBySQLBeanQuery("get_collect_folder_static", params, CollectFolderVo.class);
	}

	public void insertCollectFolder(Map<String, Object> params) {
		params.put("id", IdCreater.getId());
		templateQLService.executeSQLUpdate("insert_collect_folder", params);
	}

	public void delCollectInfo(Long id) {
		Map<String, Long> param = new HashMap<String, Long>();
		param.put("id", id);
		templateQLService.executeSQLUpdate("delete_collect_info", param);
	}
	
	public void delCollectFolder(Long id) {
		Map<String, Long> param = new HashMap<String, Long>();
		param.put("id", id);
		templateQLService.executeSQLUpdate("delete_collect_folder", param);
		
	}

	@Override
	public void editCollectInfo(Long id, String folderName) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("id", id);
		param.put("folder_nm", folderName.toString());
		templateQLService.executeSQLUpdate("edit_collect_folder", param);
		
	}
	
	public Page<CollectFolderVo> getCollectFolder(Map<String, Object> params) {
		Integer pageIndex = (Integer) params.get(Constants.PAGE_INDEX_KEY);
		Integer pageSize = (Integer) params.get(Constants.PAGE_SIZE_KEY);
		return templateQLService.findByPagedSQLBeanQuery("get_collect_folder_static", params,
				Page.getStartOfPage(pageIndex, pageSize), pageSize, CollectFolderVo.class);
	}

}
